<div class="am-cf am-form-group">
    <label class="am-u-sm-2 am-form-label">{$field.title|htmlspecialchars}</label>
    <if condition="$field['name'] == 'action'">
        <p style="color: #f00;">开发人员注意：你使用了一个名称为action的字段，由于这个字段名称会与form[action]冲突，导致无法提交表单，请换用另外一个名字。</p>
    </if>
    <div class="am-u-sm-10 ">
    <switch name="field.type">
        <case value="text">
            <input type="text" name="{$field.name}" value="{$field.value|htmlspecialchars}" class="am-form-field" style="width: 400px"/>
        </case>

        <case value="label">
            {$field.value}
        </case>

        <case value="hidden">
            <input type="hidden" name="{$field.name}" value="{$field.value}" class="am-form-field"/>
        </case>
        <case value="readonly">
            <input type="text" name="{$field.name}" value="{$field.value}" class="am-form-field" placeholder="无需填写" readonly/>
        </case>
        <case value="integer">
            <input type="text" name="{$field.name}" value="{$field.value}" class="am-form-field" />
        </case>
        <case value="uid">
            <input type="text" name="{$field.name}" value="{$field.value}" class="am-form-field" />
        </case>
        <case value="select">
            <select name="{$field.name}" class="am-form-field" style="width:auto;">
                <volist name="field.opt" id="option">
                    <php>
                        $selected = $field['value']==$key ? 'selected' : '';
                    </php>
                    <option value="{$key}"
                    {$selected}>{$option|htmlspecialchars}</option>
                </volist>
            </select>
        </case>
        <case value="radio">
            <volist name="field.opt" id="option">
                <php>
                    $checked = $field['value']==$key ? 'checked' : '';
                    $inputId = "id_$field[name]_$key";
                </php>
                <label for="{$inputId}"> <input id="{$inputId}" name="{$field.name}" value="{$key}" type="radio" {$checked}/> {$option|htmlspecialchars}</label>
            </volist>
        </case>

        <case value="singleImage">
            <div class="controls">
                <div id="upload_single_image_{$field.name}" style="padding-bottom: 5px;">选择图片</div>
                <input class="attach" type="hidden" name="{$field.name}" value="{$field['value']}"/>
                <div class="upload-img-box">
                    <div class="upload-pre-item popup-gallery">

                    <notempty name="field.value">
                        <div class="each">
                        <a href="{$field.value|get_cover='path'}" title="点击查看大图">
                            <img src="{$field.value|get_cover='path'}">
                        </a>
                            <div class="text-center opacity del_btn" ></div>
                            <div onclick="admin_image.removeImage($(this),'{$field.value}')"  class="text-center del_btn">删除</div>
                        </div>
                    </notempty>
                    </div>
                </div>
            </div>
            <script>
                $(function () {
                    var uploader_{$field.name}= WebUploader.create({
                        // 选完文件后，是否自动上传。
                        auto: true,
                        // swf文件路径
                        swf: 'Uploader.swf',
                        // 文件接收服务端。
                        server: "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#upload_single_image_{$field.name}',
                        // 只允许选择图片文件。
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/*'
                        }
                    });
                    uploader_{$field.name}.on('fileQueued', function (file) {
                        uploader_{$field.name}.upload();
                    });
                    /*上传成功*/
                    uploader_{$field.name}.on('uploadSuccess', function (file, data) {
                        if (data.status) {
                            $("[name='{$field.name}']").val(data.id);
                            $("[name='{$field.name}']").parent().find('.upload-pre-item').html(
                                    ' <div class="each"><a href="'+ data.path+'" title="点击查看大图"><img src="'+ data.path+'"></a><div class="text-center opacity del_btn" ></div>' +
                                            '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>'
                            );
                            uploader_{$field.name}.reset();
                        } else {
                            updateAlert(data.info);
                            setTimeout(function () {
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled', false);
                            }, 1500);
                        }
                    });
                })
            </script>

        </case>

        <case value="multiImage">
            <div class="controls multiImage">
                <div id="upload_multi_image_{$field.name}" style="padding-bottom: 5px;">选择图片</div>
                <input class="attach" type="hidden" name="{$field.name}" value="{$field['value']}"/>
                <div class="upload-img-box">
                    <div class="upload-pre-item popup-gallery">

                        <notempty name="field.value">
                            <php>$aIds = explode(',',$field['value']);</php>
                            <volist name="aIds" id="aId">
                                <div class="each">
                                    <a href="{$aId|get_cover='path'}" title="点击查看大图">
                                        <img src="{$aId|get_cover='path'}">
                                    </a>
                                    <div class="text-center opacity del_btn" ></div>
                                    <div onclick="admin_image.removeImage($(this),'{$aId}')"  class="text-center del_btn">删除</div>
                                </div>
                            </volist>


                        </notempty>
                    </div>
                </div>
            </div>
            <script>
                $(function () {
                    var id = "#upload_multi_image_{$field.name}";
                    var limit = parseInt('{$field.opt}');
                    var uploader_{$field.name}= WebUploader.create({
                        // 选完文件后，是否自动上传。
                          // swf文件路径
                        swf: 'Uploader.swf',
                        // 文件接收服务端。
                        server: "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        //pick: '#upload_multi_image_{$field.name}',
                        pick: {'id': id, 'multi': true},
                        fileNumLimit: limit,
                        // 只允许选择图片文件。
                        accept: {
                            title: 'Images',
                            extensions: 'gif,jpg,jpeg,bmp,png',
                            mimeTypes: 'image/*'
                        }
                    });
                    uploader_{$field.name}.on('fileQueued', function (file) {
                        uploader_{$field.name}.upload();
                    });
                    uploader_{$field.name}.on('uploadFinished', function (file) {
                        uploader_{$field.name}.reset();
                    });
                    /*上传成功*/
                    uploader_{$field.name}.on('uploadSuccess', function (file, data) {
                              if (data.status) {
                                var ids = $("[name='{$field.name}']").val();
                                ids = ids.split(',');
                              if( ids.indexOf(data.id) == -1){
                                    var rids = admin_image.upAttachVal('add',data.id, $("[name='{$field.name}']"));
                                  if(rids.length>limit){
                                      updateAlert('超过图片限制');
                                      return;
                                  }
                                  $("[name='{$field.name}']").parent().find('.upload-pre-item').append(
                                            ' <div class="each"><a href="'+ data.path+'" title="点击查看大图"><img src="'+ data.path+'"></a><div class="text-center opacity del_btn" ></div>' +
                                                    '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>'
                                    );
                                }else{
                                    updateAlert('该图片已存在');
                                }
                            } else {
                                updateAlert(data.info);
                                setTimeout(function () {
                                    $('#top-alert').find('button').click();
                                    $(that).removeClass('disabled').prop('disabled', false);
                                }, 1500);
                            }
                    });
                })
            </script>

        </case>

        <case value="checkbox">
            <php>
                $importCheckBox = true;
            </php>
            <php>
                $field['value_array'] = explode(',', $field['value']);
            </php>
            <volist name="field.opt" id="option">
                <php>
                    $checked = in_array($key,$field['value_array']) ? 'checked' : '';
                    $inputId = "id_$field[name]_$key";
                </php>
                <label for="{$inputId}"> <input type="checkbox" value="{$key}" id="{$inputId}" class="oneplus-checkbox" data-field-name="{$field.name}" {$checked}/> {$option|htmlspecialchars}</label>

            </volist>
            <input type="hidden" name="{$field.name}" class="oneplus-checkbox-hidden" data-field-name="{$field.name}" value="{$field.value}"/>
        </case>
        <case value="editor">
                {:W('Common/Ueditor/editor',array($field['name'],$field['name'],$field['value'],$field['style']['width'],$field['style']['height'],$field['config']))}
        </case>
        <case value="textarea">
            <textarea name="{$field.name}" class="am-form-field" >{$field.value|htmlspecialchars}</textarea>
        </case>
        <case value="time">
            <php>
                $importDatetimePicker = true;
                //默认为当前时间
                if(!$field['value']){
                $field['value'] = time();
                }
            </php>
            <input type="hidden" name="{$field.name}" value="{$field.value}"/>
            <input type="text" data-field-name="{$field.name}" class="time am-form-field" value="{$field.value|time_format}" placeholder="请选择时间"/>
        </case>

        <!--添加城市选择（需安装城市联动插件,css样式不好处理排版有点怪）-->
        <case value="city">
                <style type="text/css">
        			.am-form-field {
    				display:inline-block;
    				width: 120px;
    				}
    			</style>
                <!--修正在编辑信息时无法正常显示已经保存的地区信息-->
                {:hook('J_China_City',array('province'=>$field['value']['0'],'city'=>$field['value']['1'],'district'=>$field['value']['2'],'community'=>$field['value']['3']))}
        </case>

        <!--弹出窗口选择并返回值（目前只支持返回ID）开始-->
        <case value="dataselect">
            <input type="text" name="{$field.name}" id="{$field.name}" value="{$field.value|htmlspecialchars}" class="am-form-field"/><input class="am-btn am-btn-default" style="margin-left:10px" type="button" value="选择" onclick="openwin('{$field.opt}','600','500')">
    			     <script type="text/javascript">
    						//弹出窗口
    						function openwin(url,width,height){
    						    var l=window.screen.width ;
    						    var w= window.screen.height;
    						    var al=(l-width)/2;
    						    var aw=(w-height)/2;
    						    var OpenWindow=window.open(url,"弹出窗口","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width="+width+",height="+height+",top="+aw+",left="+al+"");
    						    OpenWindow.focus();
    						if(OpenWindow!=null){ //弹出窗口关闭事件
    						//if(window.attachEvent) OpenWindow.attachEvent("onbeforeunload",   quickOut);
    						if(window.attachEvent) OpenWindow.attachEvent("onunload",   quickOut);
    						}
    						}
    						//关闭触发方法
    						function quickOut()
    						{
    						alert("窗口已关闭");
    						}
    				 </script>
        </case>
    	<!--弹出窗口选择并返回值（目前只支持返回ID）结束-->

        <case value="kanban">

            <input type="hidden" name="{$field.name}" value='{:json_encode($field["value"])}'/>
            <div class="kanbans" id="{$field.name}">
                <php>foreach($field['value'] as $key =>$kanban){</php>
                <div class="kanban panel" data-id="{$kanban['data-id']}" data-title="{$kanban['title']}">
                    <div class="panel-heading">
                        <strong>{$kanban['title']}</strong>
                    </div>
                    <div class="panel-body">
                        <div class="kanban-list">
                            <volist name="kanban.items" id="vo">
                                <div class="kanban-item item" data-id="{$vo.data-id}" data-title="{$vo.title}">
                                    {$vo.title}
                                </div>
                            </volist>
                        </div>
                    </div>
                </div>
                <php>}</php>
            </div>
            <script>
                $(function () {
                    var flag = "{$field.name}"
                    $('#{$field.name}').kanbans({'drop': function () {
                        var kanban =new Array();
                        $('.kanbans .kanban').each(function (index, element) {
                            if ($(element).data('id')) {
                                kanban[index] =  new Object();
                                kanban[index]['data-id'] =  $(element).data('id');
                                kanban[index]['title'] =  $(element).data('title');
                                kanban[index]['items'] =  new Array();
                                var obj = $(element).find('.item');
                                for (var i = 0; i < obj.length; i++) {
                                    kanban[index]['items'][i] = new Object();
                                    kanban[index]['items'][i]['data-id'] = $(obj[i]).data('id');
                                    kanban[index]['items'][i]['title'] = $(obj[i]).data('title');
                                };
                            }
                        })
                        var kanban_str = JSON.stringify(kanban);
                        $('[name="'+flag+'"]').val(kanban_str);
                    }
                    })
                })
            </script>

        </case>
    <case value="chosen">
        <select name="{$field.name}[]" class="chosen-select" multiple="multiple">
            <php>
                if( key($field['opt']) === 0){
            </php>
            <volist name="field['opt']" id="option">
                <php>
                    $selected = in_array(reset($option),$field['value'])? 'selected' : '';
                </php>
                <option value="{:reset($option)}" {$selected}>{$option|end|htmlspecialchars}</option>
            </volist>
            <php>
                }else{
                foreach($field['opt'] as $optgroupkey =>$optgroup){
            </php>
            <optgroup label="{$optgroupkey}">
                <volist name="optgroup" id="option">
                    <php>
                        $selected = in_array(reset($option),$field['value'])? 'selected' : '';
                    </php>
                    <option value="{:reset($option)}" {$selected}>{$option|end|htmlspecialchars}</option>
                </volist>
            </optgroup>
            <php>
                }
                }
            </php>
        </select>
    </case>

        <case value="multiInput">
            <div class="clearfix" style="{$field['style']}">
            <php>
                $field['name'] = is_array($field['name'])?$field['name']:explode('|',$field['name']);
                foreach($field['name'] as $key=>$val){
            </php>
            <switch name="field['config'][$key]['type']">
                <case value="text">
                    <input type="text" name="{$val}" value="{$field['value'][$key]|htmlspecialchars}" class=" pull-left am-form-field" style="{$field['config'][$key]['style']}" placeholder="{$field['config'][$key]['placeholder']}"/>
                </case>
                <case value="select">
                    <select name="{$val}" class="pull-left am-form-field" style="{$field['config'][$key]['style']}" >
                        <php>foreach($field['config'][$key]['opt'] as $key_opt =>$option){</php>
                        <php>
                            $selected = $field['value'][$key]==$key_opt ? 'selected' : '';
                        </php>
                        <option value="{$key_opt}"{$selected}>{$option|htmlspecialchars}</option>
                        <php>}</php>
                    </select>
                </case>
            </switch>
            <php>
                }
            </php>
            </div>
        </case> 
        <default/>
        <span style="color: #f00;">错误：未知字段类型 {$field.type}</span>
        <input type="hidden" name="{$field.name}" value="{$field.value|htmlspecialchars}"/>
        </switch>
        <if condition="$field['subtitle']">
        <span class="am-form-help">（{$field.subtitle|htmlspecialchars}）</span>
        </if>
    </div>
</div>